package chkui.springcore.example.hybrid.beanmanipulation.propertyEditor;

import java.beans.PropertyEditorSupport;

import chkui.springcore.example.hybrid.beanmanipulation.bean.Address;

public class AddressEditor extends PropertyEditorSupport {
	private String[] SPLIT_FLAG = { ",", "-", ";", ":" };

	public void setAsText(String text) {
		int pos = -1;
		Address address = new Address();
		for (String flag : SPLIT_FLAG) {
			pos = text.indexOf(flag);
			if (-1 < pos) {
				String[] split = text.split(flag);
				address.setProvince(split[0]);
				address.setCity(split[1]);
				address.setDistrict(split[2]);
				break;
			}
		}
		if (-1 == pos) {
			throw new IllegalArgumentException("地址格式错误");
		}
		setValue(address);
	}
}
